package sketch.specs;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.Comment;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.MethodDeclaration;

import sketch.ast.ASTUtils;
import sketch.generator.JUnitTestCreator;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class CreatingTest extends TestCase {
	
	public static Test suite() {
		return new TestSuite(CreatingTest.class);
	}
	
	public void testCreateExpandedTest() {
		System.out.println("\n\n executing testCreateExpandedTest ----\n\n");
		String filePath = "./tests/sketch/specs/samplecode.txt";;
		SketchedMethodsCreator creator = new SketchedMethodsCreator(filePath);
		List<SketchedMethodDeclaration> sketchedMethods = creator.createSketchedMethodList();
		
		assertTrue(sketchedMethods.size() == 7);
		
		StringBuilder testCollection = new StringBuilder();
		for(SketchedMethodDeclaration sketchedMethod : sketchedMethods) {
			String methodName = sketchedMethod.method_declaration.getName().toString();
			System.out.println(" processing method: " + methodName);
			if(!methodName.equals("rewriteSize")) {
				continue;
			}
			List<MethodDeclaration> methods = sketchedMethod.getMethodsAfterExpansion();
			for(MethodDeclaration m : methods) {
				testCollection.append(m.toString());
//				System.out.println(m);
			}
		}
		
		CompilationUnit unit = creator.getUnit();
		String[] imports = ASTUtils.extractImportDeclarationAsString(unit);
		
		//create the tests
		JUnitTestCreator.createJUnitTest(testCollection.toString(), ".", "TestExpansion", imports);
	}
	
	public void testCreateNestedRepeatTest() {
		System.out.println("Testing expanding nested repeat!");
		String filePath = "./tests/sketch/specs/nestedrepeat.txt";;
		SketchedMethodsCreator creator = new SketchedMethodsCreator(filePath);
		List<SketchedMethodDeclaration> sketchedMethods = creator.createSketchedMethodList();
		
		StringBuilder testCollection = new StringBuilder();
		for(SketchedMethodDeclaration sketchedMethod : sketchedMethods) {
			
			List<MethodDeclaration> methods = sketchedMethod.getMethodsAfterExpansion();
			for(MethodDeclaration m : methods) {
				testCollection.append(m.toString());
//				System.out.println(m);
			}
		}
		
		CompilationUnit unit = creator.getUnit();
		String[] imports = ASTUtils.extractImportDeclarationAsString(unit);
		
		//create the tests
		JUnitTestCreator.createJUnitTest(testCollection.toString(), ".", "TestNestedExpansion", imports);
	}
}